Imports Microsoft.VisualBasic
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System
Imports System.Data
Imports GTSDAL
Imports GTSDALTableAdapters
Imports GTSSystem.BLL.IdGenerator

Namespace GTSSystem.BLL
    <System.ComponentModel.DataObject()> _
Public Class Contract

        Private _contractAdaptor As ContractTableAdapter = Nothing
        Private _contractInfoAdaptor As ContractINFOTableAdapter = Nothing

        Protected ReadOnly Property ContractAdaptor() As ContractTableAdapter
            Get
                If _contractAdaptor Is Nothing Then
                    _contractAdaptor = New ContractTableAdapter
                End If
                Return _contractAdaptor
            End Get
        End Property

        Protected ReadOnly Property ContractInfoAdaptor() As ContractINFOTableAdapter
            Get
                If _contractInfoAdaptor Is Nothing Then
                    _contractInfoAdaptor = New ContractInfoTableAdapter
                End If
                Return _contractInfoAdaptor
            End Get
        End Property

        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
        Public Function getContract() As ContractDataTable
            Try
                Return ContractAdaptor.GetContract()
            Catch ex As Exception
                Throw
            End Try
        End Function

        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
        Public Function GetContractByClientBranchID(ByVal ClientBranchID As Integer) As ContractDataTable
            Try
                Return ContractAdaptor.GetContractByClientBranchID(ClientBranchID)
            Catch ex As Exception
                Throw
            End Try
        End Function
        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
        Public Function GetContractInfoByClientBranchID(ByVal ClientBranchID As Integer) As ContractINFODataTable
            Try
                Return ContractInfoAdaptor.GetContractINFOByClientBranchID(ClientBranchID)
            Catch ex As Exception
                Throw
            End Try
        End Function

        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
        Public Function GetContractInfoByContractID(ByVal ContractID As Integer) As ContractINFODataTable
            Try
                Return ContractInfoAdaptor.GetContractINFOByContractID(ContractID)
            Catch ex As Exception
                Throw
            End Try
        End Function

        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Insert, True)> _
        Public Function AddContract(ByVal ClientID As Integer, _
                                ByVal ClientBranchID As Integer, _
                                ByVal CarrierID As Integer, _
                                ByVal ContractStartDate As Date, _
                                ByVal ContractEndDate As Date) As Integer
            Dim ContractPK As Integer
            Dim StatusID As Integer = 1
            Try
                ContractPK = GetNextId("Contract")
                ContractAdaptor.Insert(ContractPK, ClientID, ClientBranchID, CarrierID, StatusID, ContractStartDate, ContractEndDate)
            Catch ex As Exception
                Throw
            End Try
        End Function

        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Update, False)> _
        Public Sub UpdateStatus(ByVal ContractID As Integer, _
                            ByVal StatusID As Integer)

            Try
                ContractAdaptor.UpdateStatus(ContractID, StatusID)
            Catch ex As Exception
                Throw
            End Try
        End Sub
    End Class
End Namespace
